#include <sstream>

#include "GenericException.hpp"
#include "ConnectionHandlerMixnode.hpp"
#include "ListenSocket.hpp"
#include "Logger.hpp"

int protected_main(int argc, char **argv) {
	if (argc != 4) {
		std::cerr << "Syntax:" << std::endl;
		std::cerr << argv[0] << " <CA certificate> <local certificate> <local key>" << std::endl;
		exit(1);
	}

	ListenSocket socket = ListenSocket(IP("127.0.0.1"), 4433);
	while (true) {
		ConnectionHandler* newConn = new ConnectionHandlerMixnode(argv[1], argv[2], argv[3]);
		socket.handleConnection(newConn);
		Logger::log(Logger::INFO, "Host connected to server.");
	}
	return 0;
}

int main(int argc, char **argv) {
//	return protected_main(argc, argv);
	
	try {
		return protected_main(argc, argv);
	} catch (const GenericException &E) {
		E.terminate();
	}
	return 1;
}

